/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package tank.views;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import tank.controllers.TankSelectController;
import tank.models.GameSettings;
import tank.models.Global;

/**
 *
 * @author shengchang
 */
public class TankSelectView extends JPanel{
    private TankSelectController controller;

    /**
     *
     */
    public TankSelectView(TankSelectController controller)
    {
        this.controller = controller;
        this.addMouseListener(controller);
        this.addMouseMotionListener(controller);
    }
            
    @Override
    public void paint(Graphics g)
    {
        //draw background of select view
        drawBackground(g);
        
        //draw enemy tank type
        drawTankSelection(g, Global.enemyTankTypeVector.get(Global.enemyTankType),1, 199, 202, 202);
        
        //draw my tank type
        drawTankSelection(g, Global.myTankTypeVector.get(Global.myTankType),599, 199, 202, 202);
        
        //draw map background type
        drawTankSelection(g, Global.mapBackgroundTypeVector.get(Global.mapBackgroundType),299, 0, 202, 150);
    }
    
    /**
     *
     * @param g
     */
    public void drawBackground(Graphics g)
    {
        try {
            g.drawImage(ImageIO.read(new File(GameSettings.defaultBackgroundImgPath)), 0, 0, GameSettings.gameWindowSizeX, GameSettings.gameWindowSizeY, null);
        } catch (IOException ex) {
            Logger.getLogger(TankSelectView.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }       
    
    public void drawTankSelection(Graphics g, Image image,int x, int y, int w, int h)
    {
        g.setColor(Color.orange);
        g.draw3DRect(x, y, w, h, true);
        g.drawImage(image, x, y, w-2, h-2, this);
    }
}
